extends ./layout.jade

block head
	link(rel='stylesheet',href='/lib/simditor/styles/simditor.css')
	link(rel='stylesheet',href='/lib/simditor-mention/styles/simditor-mention.css')

block sidebar
	.ui.segment='侧边'

block body
	.ui.tabular.menu
		a.item(href='/tab/all',class=(!tabId||tabId=='all')?'active':'') 全部
		each tab in tabs
			a.item(href='/tab/'+tab._id,class=(tab._id==tabId)?'active':'')=tab.name
		.right.menu
			.ui.dropdown.item 按热门程度
				i.dropdown.icon
				.menu
					a.item 按热门程度
					a.item 按时间顺序
		//-.selection.very
	.ui.divided.relaxed.list
		each topic in topics
			.item
				.tc.ui.mini.left.floated.labels
					.ui.label(class=topic.replyCount==0?'red':'teal')
						=topic.replyCount
						br
						='评论'
					.ui.label
						=topic.views
						br
						='浏览'
				.content
					.description
						a.gray(href='/user/'+topic.authorId)=topic.authorName
						!='&nbsp&nbsp&nbsp'
						span.gray.ml5=topic.createAtformatted
					h3.black.header
						a(href='/tab/'+topic.tabId)='['+tabs[topic.tabId].name+']'
						a(href='/topic/'+topic._id)=topic.title
					.description
						each tag in topic.tags
							a.ui.mini.label(href='/tag/'+tag)=tag
	.ui.basic.center.aligned.segment
		.ui.borderless.pagination.menu
			include ./include/pagination.jade
			+pagination('/tab/'+tabId+'/{page}',page,pageTotal)
	- if(locals.user)
		.ui.segment
			h3.header 快速发表主题
			form#form-post
				.ui.form
					.fields
						.ten.wide.field
							input.large(type='text',placeholder='标题：必填',name='title',required)
						.six.wide.field
							select.ui.dropdown(name='tabId')
								each tab in tabs
									option(value=tab._id)=tab.name
					.field
						input(type='text',placeholder='标签：可选，逗号、分号、空格分隔',name='tags')
					.field
						textarea#editor(rows='8',name='content',placeholder='内容：不能为空',required)
					.ui.error.message#msg-post
					button.ui.blue.submit.labeled.icon.button 发表
						i.signup.icon

block script
	script.
		$('.ui.dropdown').dropdown();

	- if(locals.user)
		script(src='/lib/simple-module/lib/module.js')
		script(src='/lib/simple-hotkeys/lib/hotkeys.js')
		script(src='/lib/simditor/lib/simditor.js')
		script(src='/lib/simditor-mention/lib/simditor-mention.js')
		script.
			var editor=new Simditor({
				textarea:$('#editor'),
				mention:{
					url:'/mentionedUsers',
					linkRenderer:function($linkEl,data){
						$linkEl.attr('data-uid',data.id);
					}
				}
			});
			// $(editor).on("mention",function(e,el,data){
			// 	color = ( data.id%2==0? 'blue' : 'red' )
			// 	$(el).css('color',color);
			// });
			
		include ./include/validate.jade
		script.
			//发表主题
			$('#form-post').validateInit({
				submitHandler:function(form){
					$('#form-post .form').addClass('loading');
					$.post('/topic/create',$('#form-post').serializeJson(),function(data){
						if(data.result=='success')
							window.location.reload();
						else
							$('#msg-post').text(data.msg).show();
						$('#form-post .form').removeClass('loading');
					},'json');
				}
			});